package cc.yugu.yhdw.webserver.config;

import cc.yugu.yhdw.common.entity.AreaCache;
import cc.yugu.yhdw.webserver.service.basic.AreaService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
 * 获取自定义的bean实例，并进行相应的地点设置
 *
 * @Date:Created in 2018/6/27 10:45
 * @Author:
 * @Modified By: zjn 2018/6/27 10:45
 */
public class SpringApplicationContextAware implements ApplicationContextAware {
    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        AreaService areaService = context.getBean(AreaService.class);
        //返回与给定对象类型唯一匹配的bean实例
        AreaCache areaCache = context.getBean(AreaCache.class);
        //将查询表bas_area所有的地区数据以及城市名添加到areaCache对象中
        areaCache.set(areaService.findAll(), areaService.findAllCity());
    }
}
